<style >
    #tableIconForBizDemand + .layui-table-view .layui-table-body tbody > tr > td {
        padding: 0;
    }

    #tableIconForBizDemand + .layui-table-view .layui-table-body tbody > tr > td > .layui-table-cell {
        height: 60px;
        line-height: 60px;
    }

    .tdImg {
        width: 35px;
        height:35px;
        max-width: none;
        cursor: pointer;
    }

    .layui-table-view {
        margin: 0;
    }
</style>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body table-tool-mini">
            <div class="layui-form toolbar" id="tbToolBar">
                <div class="layui-form-item">
					<div class="layui-inline">
						<button id="btnAddBizDemand" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>新增</button>
						<span style="color:red;">合理的佣金能激发程序员的积极性！！！</span>
					</div>
                    <div class="layui-inline" style="float: right;margin-right: 0px;">
						<div class="layui-inline" style="padding-right: 0px;margin-right: 0px;">
							<label class="layui-form-label w-auto">名称</label>
							<div class="layui-input-inline mr0">
								<input name="name" class="layui-input" type="text" placeholder="请输入名称"/>
							</div>
						</div>
						<div class="layui-inline" style="padding-right: 0px;margin-right: 0px;">
							<button class="layui-btn icon-btn" lay-filter="formSubSearchBizDemand" lay-submit>
								<i class="layui-icon">&#xe615;</i>查询
							</button>
						</div>					
					</div>
				</div>
				<table class="layui-table" id="tableBizDemand" lay-filter="tableBizDemand"></table>
			</div>
		</div>
	</div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="tableBarBizDemand">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<!-- 表格状态列 -->
<script type="text/html" id="tableStateBizDemand">
#[[  {{#  if(d.enabled === '1'){ }}
    <span style="color: #23aa2e;">已处理</span>
  {{#  } else { }}
	<span style="color: #ff0000;">待处理</span>
  {{#  } }}
]]#
</script>


<!-- 表单弹窗-->
<script type="text/html" id="modelBizDemand"> 
    <form id="modelBizDemandForm" lay-filter="modelBizDemandForm" class="layui-form model-form" style="padding: 5px;">
        <input name="id" type="hidden"  />
		<table class="formTable">
			<tr>
				<td>名称</td>
				<td colspan="3" style="text-align: left;">
                	<input name="name"  placeholder="请输入名称" type="text" class="layui-input" lay-verType="tips" lay-verify="required" required/>
                </td>
			</tr>
			<tr>
				<td>电话</td>
				<td colspan="3" style="text-align: left;">
                	<input name="timeLimit"  placeholder="请输入电话" type="text" class="layui-input" />
                </td>
			</tr>
			<tr>
				<td>时间期限</td>
				<td colspan="3" style="text-align: left;">
        			<input type="text" class="layui-input" id="timeLimit" placeholder=" - ">
                </td>
			</tr>	
			<tr>
				<td>说明</td>
				<td colspan="3" style="text-align: left;">
					<textarea name="content" placeholder="富文本实现" class="layui-textarea" style="height: 250px;"></textarea>
                </td>
			</tr>
			<tr>
				<td colspan="4">
		            <button class="layui-btn" lay-filter="modelSubmitBizDemandForm" lay-submit>保存</button>
                </td>
			</tr>												
		</table>    
    </form>
</script>


<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'util', 'admin', 'config','colorpicker','laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var admin = layui.admin;
        var config = layui.config;
        var colorpicker = layui.colorpicker;
        var laydate = layui.laydate;

        // 渲染表格
        var insTb = table.render({
            elem: '#tableBizDemand',
            url: '#(ctx)/biz/demand/listData', 
            page: true,
            toolbar: false,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers', title: '序号'},
                {field: 'name', sort: false, title: '名称'},
                {field: 'code', sort: false, title: '标识'},
                {field: 'offer', sort: false, title: '佣金'},
                {field: 'createUserName', sort: false, title: '作者'},
                {field: 'phone', sort: false, title: '联系电话'},
                {
                    field: 'createTime', sort: false, templet: function (d) {
                        return util.toDateString(d.createTime);
                    }, title: '创建时间'
                },
                {
                    field: 'timeLimit', sort: false, templet: function (d) {
                        return util.toDateString(d.createTime);
                    }, title: '时间期限'
                },
				{field: 'status', sort: false, templet: '#tableStateBizDemand', title: '状态', align: 'center'},
                {align: 'left', toolbar: '#tableBarBizDemand', title: '操作'}
            ]],
        });

        // 添加
		$('#btnAddBizDemand').click(function () {
			 showEditModel();
		});

        // 搜索
        form.on('submit(formSubSearchBizDemand)', function (data) {
            insTb.reload({where: data.field}, 'data');
        });

        // 工具条点击事件
        table.on('tool(tableBizDemand)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'edit') { // 修改
            	showEditModel(data);
            } else if (layEvent === 'del') { // 删除
                doDel(data.id, data.name);
            }
        });

        // 删除
        function doDel(id, name) {
            layer.confirm('确定要删除“【<span style="color:red;">' + name + '</span>】”吗？', {
                skin: 'layui-layer-admin',
                shade: .1
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('biz/demand/delete', {
                    id: id
                }, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.message, {icon: 1});
                        insTb.reload({}, 'data');
                    } else {
                        layer.msg(res.message, {icon: 2});
                    }
                }, 'get');
            });
        }


        // 显示表单弹窗
        function showEditModel(data) {
            layer.open({
                type: 1,
                shade: 0.3,
                offset: 't'	,
                title: (data ? '修改' : '添加') + '',
                area:'500px',
                resize :false,
                content: $('#modelBizDemand').html(),
                success: function (layero, dIndex) {
                    $(layero).children('.layui-layer-content').css('overflow', 'visible');
                    form.val('modelBizDemandForm', data);  // 回显数据
                    
                    //日期范围
                    laydate.render({
                      elem: '#timeLimit'
                      ,range: true
                    });
    			    form.on('submit(modelSubmitBizDemandForm)', function (data) {
    			        layer.load(2);
    			        var formData={}; 
    			        for(var key in data.field){
    			        	formData['bizDemand.'+key]=data.field[key];
    			        }
                        admin.req("biz/demand/save",formData, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.close(dIndex);
                                layer.msg(res.message, {icon: 1});
                                insTb.reload({}, 'data');
                            } else {
                                layer.msg(res.message, {icon: 2});
                            }
                        }, 'get');
    			        return false;
    			    });
    			    form.render(); 
                },
                end:function(){
                }
            });
        }
    });
    
</script>
